using System;
using System.Collections.Generic;
using System.Text;

namespace Kopain.Exception
{

    // For guidelines regarding the creation of new exception types, see
    //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
    // and
    //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp


    /// <summary>This is the base exception of exceptions of this application.
    /// It shouldn't be instantiated but inherited from.
    /// </summary>
    [global::System.Serializable]
    internal class KopainException : ApplicationException
    {
        internal KopainException( string message, System.Exception innerException )
            : base( message, innerException )
        {
        }
    }


    /// <summary>This exception should be thrown when an expected file wasn't found.
    /// </summary>
    [global::System.Serializable]
    internal class FileWasNotFoundException : KopainException
    {
        private string _filename;

        public string Filename
        {
            get { return _filename; }
        }

        internal FileWasNotFoundException( string filename, System.IO.FileNotFoundException innerException )
            :
            base( string.Format( "The file {0} was not found.", filename ), innerException )
        {
            _filename = filename;
        }
    }


    /// <summary>This exception should be thrown when an expected path wasn't found.
    /// </summary>
    [global::System.Serializable]
    internal class DirectoryWasNotFoundException : KopainException
    {
        private string _path;

        public string Path
        {
            get { return _path; }
        }


        /// <summary>Constructor.
        /// </summary>
        /// <param name="path">Path without filename.</param>
        /// <param name="innerException"></param>
        internal DirectoryWasNotFoundException( string path, System.IO.DirectoryNotFoundException innerException )
            :
            base( string.Format( "The path {0} was not found.", path ), innerException )
        {
            _path = path;
        }
    }


    /// <summary>This exception should be thrown when the user wanted to move in a direction that doesn' work.
    /// It should not be thrown every time because the treeview should figure out when it is possible to move and
    /// when not.  But if there is an error in the treeview code and a "move" slips through to the Note objects this
    /// exception should be thrown instead of the letting code handling it so the bug surfaces and can be gotten
    /// rid of.
    /// </summary>
    [global::System.Serializable]
    internal class IllegalDirection : KopainException
    {
        private NoteType.MoveDirection _direction;

        public NoteType.MoveDirection Direction
        {
            get { return _direction; }
        }

        internal IllegalDirection( NoteType.MoveDirection direction )
            :
            base( string.Format( "It is not allowed to move the Note in the {0} direction.", direction ), null )
        {
            _direction = direction;
        }
    }


    /// <summary>This exception should be thrown when the Savefile is corrupt.
    /// </summary>
    [global::System.Serializable]
    internal class CorruptSaveFile : KopainException
    {

        /// <summary>The corrupt Note.
        /// </summary>
        private NoteType _note;


        /// <summary>Getter for the corrupt Note.
        /// </summary>
        public NoteType Note
        {   
            get { return _note; } 
        }


        /// <summary>Use this constructor when we don't know what is wrong with the Savefile.
        /// </summary>
        /// <param name="exc"></param>
        internal CorruptSaveFile( System.Xml.XmlException exc )
            :
            base( string.Format( "The Savefile seems corrupt by unknown reason."), exc )
        {
            _note = null;
        }


        /// <summary>Use this constructor when we know which Note is corrupt.
        /// </summary>
        /// <param name="corruptNote"></param>
        internal CorruptSaveFile( NoteType corruptNote )
            :
            base( string.Format( "The note {0} is corrupt.", corruptNote.id ), null )
        {
            _note = corruptNote;
        }
    }


    /// <summary>This exception should be thrown when the Settings file is corrupt.
    /// </summary>
    [global::System.Serializable]
    internal class CorruptSettingsFile : KopainException
    {

        /// <summary>A constructor.  Yup.
        /// </summary>
        /// <param name="exc"></param>
        internal CorruptSettingsFile( System.Xml.XmlException exc )
            :
            base( string.Format( "The Setting file seems corrupt by unknown reason." ), exc )
        {
        }

    }


    /// <summary>This exception is called if there are so many Notes with the same name that the application
    /// cannot find a unique name for it.  In realiy: this will not happen.
    /// </summary>
    [global::System.Serializable]
    internal class TooManySimilarTitlesToExport : KopainException
    {

        /// <summary>The filename where a unique name cannot be found.
        /// </summary>
        private string _filename;


        /// <summary>A getter filename where a unique name cannot be found.
        /// </summary>
        public string Filename
	    {
	      get { return _filename;}
	    }


        /// <summary>The constructor.
        /// </summary>
        /// <param name="filename">The filename that couldn't be transformed to a unique name.</param>
        internal TooManySimilarTitlesToExport( string filename )
            :base( "The export procedure can only handle a branch with so many Notes with the same Title", null )
        {
            _filename = filename;
        }
    }

}